package recycle.impl;

import org.springframework.stereotype.Service;
import recycle.dao.ProductcategoryMapper;
import recycle.pojo.Productcategory;
import recycle.service.ProductcategoryService;
import recycle.utils.Page;
import recycle.vo.ProductcategoryParam;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
* 描述：商品分类表 服务实现层接口
* @author 孙冉
* @date 2019/07/22
*/
@Service
public class ProductcategoryServiceImpl implements ProductcategoryService{
	@Resource
	private ProductcategoryMapper productcategoryMapper;
 	
 	/**
    * 描述：根据Id获取Productcategory对象
    * @param id
    */
    public Productcategory findById(Serializable categoryId){
    	return productcategoryMapper.findById(categoryId);
    }
    /**
    * 描述：获取所有的Productcategory对象
    */
    public List<Productcategory> findAll(){
    	return productcategoryMapper.findAll();
    }

	/**
    * 描述：新增保存Productcategory对象
    */
    public int save(Productcategory productcategory){
    	return  productcategoryMapper.save(productcategory);
    }

	/**
    * 描述：根据Id删除Productcategory对象
    * @param id
    */
    public int delete(Serializable categoryId){
    	return  productcategoryMapper.delete(categoryId);
    }
	
	/**
    * 描述：更新Productcategory对象
    */
    public int update(Productcategory productcategory){
    	return  productcategoryMapper.update(productcategory);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Productcategory> query(ProductcategoryParam param){
    	return  productcategoryMapper.query(param);
    }


	@Override
	public List<Productcategory> selectMobileProduct() {
		return productcategoryMapper.selectMobileProduct();
	}

	@Override
	public List<Productcategory> selectComputerProduct() {
		return productcategoryMapper.selectComputerProduct();
	}

	@Override
	public List<Productcategory> selectPadProduct() {
		return productcategoryMapper.selectPadProduct();
	}

	/**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(ProductcategoryParam param){
    	Page page = new Page();
    	if(param.isPage()){
			int totalCount = productcategoryMapper.getCount(param);
			int totalPageCount = (totalCount-1)/page.getPageSize()+1;
			if(param.getPageIndex()<1){
				param.setPageIndex(1);
			}else if(param.getPageIndex()>totalPageCount){
				param.setPageIndex(totalPageCount);
			}
			List list = productcategoryMapper.query(param);

			page.setTotalCount(totalCount);
			page.setTotalPageCount(totalPageCount);
    		page.setPageNo(param.getPageIndex());
    		page.setPageSize(param.getSize());
			page.setList(list);
		}
    	return page;
    	
    }

}
